<!--不受理案件弹窗-->

<template>
  <el-dialog append-to-body :title="getTitle()" width="640px" :visible="visible" @close="handleClose">
    <el-form ref="form" :model="form" :rules="rules" class="white-card" label-width="140px">
      <!-- <el-form-item label="是否公开：" prop="publishStatus">
        <el-select v-model="form.publishStatus" placeholder="请选择" style="width: 100%">
          <el-option v-for="item in publicStatusArr" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item :label="getRemarkName() + '：'" prop="result">
        <el-input v-model="form.result" show-word-limit maxlength="300" placeholder="请输入详细描述" type="textarea" :autosize="{ minRows: 4 }"></el-input>
      </el-form-item>
      <el-form-item label="结案状态：" prop="finishStatus" v-if="status === 1">
        <el-select v-model="form.finishStatus" placeholder="请选择">
          <el-option v-for="item in dictList" :key="item.id" :label="item.name" :value="item.name"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div class="split"></div>
    <div class="dialog-footer-btn">
      <el-button @click="handleClose" type="primary" plain>关闭</el-button>
      <el-button @click="handleSubmit" :loading="submitting" type="primary">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import * as mixins from "@/utils/mixins";
import * as workOrderApi from "@/api/workOrder/index";
import * as templateApi from "@/api/template";
import { dict2Array } from "@/utils/common";
import { workOrderPublicStatusDict } from "@/utils/dict";
import * as dictApi from "@/api/dict";

export default {
  name: "finallyDialog",
  mixins: [mixins.dialog, mixins.form],
  props: ["visible", "workOrderNo", "status"],
  data() {
    return {
      form: {
        // publishStatus: "N",
        finishStatus: "",
        result: "",
      },
      rules: {
        result: [{ required: true, message: "请填写" }],
        finishStatus: [{ required: true, message: "请选择" }],
      },
      title: "",
      publicStatusArr: dict2Array(workOrderPublicStatusDict),
      optionList: [],
      submitting: false,
      dictList: [],
    };
  },
  created() {},
  methods: {
    show() {
      // dictApi.list({ parentCode: "1001" })
      //   .then(res => {
      //     this.optionList = res.result;
      //   });
      /* 
        结案回访记录	1023
        同意办结备注	1011
        同意终止备注	1024
      */
      let code = null;
      switch (this.status) {
        case 1:
          code = 1011;
          this.getDictList();
          break;
        case 2:
          code = 1024;
          break;
        case 3:
          code = 1023;
          break;
        default:
          break;
      }
      templateApi.detailByCode(code).then((res) => {
        this.form.result = res.result.value;
      });
    },
    getDictList() {
      dictApi
        .list({ parentCode: "1009" })
        .then((res) => {
          this.dictList = res.result;
        })
        .finally(() => {});
    },
    handleSubmit() {
      this.validateAndConfirm("form").then((res) => {
        this.submitting = true;
        this.requestForSubmit()
          .then(() => {
            this.$emit("success");
            this.handleClose();
          })
          .finally(() => {
            this.submitting = false;
          });
      });
    },
    requestForSubmit() {
      switch (this.status) {
        case 2:
          return workOrderApi.finish.makeSureOver({
            remark: this.form.result,
            workOrderNo: this.workOrderNo,
          });
        case 3:
          return workOrderApi.finish.addVisitRecord({
            visitRecord: this.form.result,
            workOrderNo: this.workOrderNo,
          });
        default:
          return workOrderApi.distribute.finish({
            ...this.form,
            workOrderNo: this.workOrderNo,
          });
      }
    },
    getTitle() {
      switch (this.status) {
        case 2:
          return "终止案件";
        case 3:
          return "结案回访";
        default:
          return "案件办结";
      }
    },
    getRemarkName() {
      switch (this.status) {
        case 2:
          return "终止备注";
        case 3:
          return "结案回访记录";
        default:
          return "办结备注";
      }
    },
  },
};
</script>

<style scoped>
.el-select {
  width: 100%;
}
</style>
